# 火箭
# 编写一个游戏，它在屏幕中央显示一个火箭，而玩家可使用四个方向键上下左右移动火箭。请务必确保火箭不会移到屏幕外面。

import pygame
import sys

import ship


class Rocket:
    def __init__(self):
        pygame.init()

        self.screen = pygame.display.set_mode((400, 400))
        pygame.display.set_caption("火箭")

        self.ship = ship.Ship(self)

    def run(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_RIGHT:
                        self.ship.movingRight = True
                    elif event.key == pygame.K_LEFT:
                        self.ship.movingLeft = True
                    elif event.key == pygame.K_UP:
                        self.ship.movingUp = True
                    elif event.key == pygame.K_DOWN:
                        self.ship.movingDown = True
                    elif event.key == pygame.K_q:
                        sys.exit()
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_RIGHT:
                        self.ship.movingRight = False
                    elif event.key == pygame.K_LEFT:
                        self.ship.movingLeft = False
                    elif event.key == pygame.K_UP:
                        self.ship.movingUp = False
                    elif event.key == pygame.K_DOWN:
                        self.ship.movingDown = False
            self.screen.fill((0, 0, 0))
            self.ship.update()
            self.ship.blitme()
            pygame.display.flip()


if __name__ == "__main__":
    rocket = Rocket()
    rocket.run()
